home *** CD-ROM | disk | FTP | other *** search
- unit Conv;
-
- interface
-
- uses
- { Delphi needs some procedures stored in the files or 'units' listed here.
- We'll be coming back to units later in this series . }
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- { Delphi automatically generates this Type description when you design a
- form. Delphi uses an object orientated version of the Pascal language. Objects,
- such as forms, are defined as 'classes'. A new form inherits the features
- of Delphi's basic form class, TForm. Don't worry if you don't follow this.
- The good news is that you don't need to understand the details of object
- orientation to program in Delphi. Just let Delphi write these class
- definitions for you. }
- TForm1 = class(TForm)
- ConvertFromEdBox: TEdit;
- ConvertToEdBox: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- CalcBtn: TButton;
- procedure CalcBtnClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1; { Our Form, Form1 is an object of the }
- { TForm1 type, defined above. }
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.CalcBtnClick(Sender: TObject);
- { This code is attached to the CalcBtn object and is executed when the }
- { click event occurs. }
- const
- { This is the miles to kilometres conversion factor }
- mileToKM = 1.60934;
- var
- InputVal, OutputVal : Real;
- Code : integer;
- S : string;
- begin
- { First convert the text entered into the ConvertFromEdBox field to a Real }
- { value. The variable, Code, can be used for error checking. But we'll }
- { ignore it for the time being. }
- Val(ConvertFromEdBox.Text, InputVal, Code );
- { Do the calculation to convert miles to kilometres }
- OutputVal := InputVal * mileToKM;
- { Now convert the result, OutPutVal to a string. }
- Str( OutputVal:2:2, S );
- { Display the string in the ConvertToEdBox field. }
- ConvertToEdBox.Text := S;
- end;
-
- procedure CalcBtnClick;
- begin
- end;
-
- end.
-